package com.woniu40.petai_user.web;

import com.github.pagehelper.PageInfo;
import com.woniu40.petai_user.entity.Address;
import com.woniu40.petai_user.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;


import java.util.Map;

@Controller
@RequestMapping("address")
public class AddressController {

    @Autowired
    AddressService addressService;

    @RequestMapping("/addressList")
    public String addressList(@RequestParam(value = "pageNum",defaultValue = "1") Integer pageNum,
                              @RequestParam(value = "pageSize",defaultValue = "8")Integer pageSize,Map map){
        PageInfo<Address> pageInfo = addressService.findAddressByPage(pageNum,pageSize);
        map.put("pageInfo",pageInfo);
        return "";
    }

    @RequestMapping("/addAddress")
    public String addAddress(Address address){
        addressService.addAddress(address);
        return  "";
    }

    @RequestMapping("/modifyAddress")
    public String modifyAddress(Address address){
        addressService.modifyAddress(address);
        return "";
    }

    @RequestMapping("/removeAddress")
    public String removeAddress(Integer addressId){
        addressService.removeAddress(addressId);
        return "";
    }
}
